import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusCommodityByFormField/page/materialSetting/provider/material_setting_provider.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'material_item.dart';

class MaterialList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Consumer<MaterialSettingProvider>(
        builder: (context, materialSettingProvider, _) {
          return ListView.builder(
            padding: EdgeInsets.symmetric(
              horizontal: 30.w,
            ),
            itemBuilder: (context, index) {
              var current = materialSettingProvider.commodityMaterials[index];

              return MaterialItem(
                key: current.key,
                data: current,
                onDeleted: () {
                  materialSettingProvider.removeCommodityMaterials(current);
                },
                onNameChanged: (value) {
                  current.name = value;
                },
                onPriceChanged: (value) {
                  current.price = value;
                },
              );
            },
            itemCount: materialSettingProvider.commodityMaterials.length,
          );
        },
      ),
    );
  }
}
